import bpmModelApi from "@/api/declaration/bpm/bpmModelApi"
import httpRequest from "@/config/axios/httpRequest"
import { BpmModel } from "@/models/bpm/BpmProcessDefinitionModel"

export const getModelList = async (name: string | undefined) => {
  return await httpRequest.get(bpmModelApi.GetModelList, { params: { name } })
}

export const getModel = async (id: string) => {
  return await httpRequest.get(bpmModelApi.GetModel, { params: { id } })
}

export const updateModel = async (data: BpmModel) => {
  return await httpRequest.put(bpmModelApi.UpdateModel, data)
}

// 批量修改流程分类的排序
export const updateModelSortBatch = async (ids: number[]) => {
  return await httpRequest.put(bpmModelApi.UpdateModelSortBatch, { ids })
}

export const updateModelBpmn = async (data: BpmModel) => {
  return await httpRequest.put(bpmModelApi.UpdateModelBpmn, data)
}

// 任务状态修改
export const updateModelState = async (id: number, state: number) => {
  const data = {
    id: id,
    state: state
  }
  return await httpRequest.put(bpmModelApi.UpdateModelState, data)
}

export const createModel = async (data: BpmModel) => {
  return await httpRequest.post(bpmModelApi.CreateModel, data)
}

export const deleteModel = async (id: number) => {
  return await httpRequest.delete(bpmModelApi.DeleteModel, { params: { id } })
}

export const deployModel = async (id: number) => {
  return await httpRequest.post(bpmModelApi.DeployModel, { id })
}
